package bancosys.tec.datadigester.fileregistry.domain;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Comments;
import jmine.tec.persist.annotation.Index;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.MapKey;
import org.hibernate.validator.NotNull;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.authorization.annotation.DisplayName;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.persister.annotation.NaturalKey;
import bancosys.tec.persist.persister.annotation.Unique;

/**
 * Esta entidade representa as propriedades de um driver, identificado pelo seu full qualified name.
 * 
 * @author wagner
 */
@Entity
@Table(name = "DRIVER_PROPS")
@Alias("DRVPRO")
@SequenceGenerator(name = "SEQ_DRVPRO", sequenceName = "SEQ_DRVPRO")
@Documentation("PROPRIEDADES DO DRIVER.")
public class DriverProperty extends PersistableBusinessObject {
    private Long id;

    private String driverFullQualifiedName;

    private Map<String, String> properties = new HashMap<String, String>();

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_DRVPRO")
    @Column(name = "COD_DRIVER_PROPS", nullable = false)
    @Documentation("CODIGO DA PROPRIEDADE DO DRIVER")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the driverFullQualifiedName
     */
    @Column(name = "DRV_NAME", nullable = false)
    @Documentation("FULL QUALIFIED NAME DO DRIVER.")
    @Unique
    @NotNull
    @NaturalKey
    public String getDriverFullQualifiedName() {
        return this.driverFullQualifiedName;
    }

    /**
     * @param driverFullQualifiedName the driverFullQualifiedName to set
     */
    public void setDriverFullQualifiedName(String driverFullQualifiedName) {
        this.driverFullQualifiedName = driverFullQualifiedName;
    }

    /**
     * Mapa de propriedades para valor do driver.
     * 
     * @return the mapaLongSemCascade
     */
    @Index(suffix = "JT_0", columns = "COD_DRIVER_PROPS")
    @CollectionOfElements
    @Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    @JoinTable(name = "DRV_MAP_PROPERTIES", joinColumns = @JoinColumn(name = "COD_DRIVER_PROPS"))
    @Alias("DRVMPR")
    @DisplayName("MAPA DE DRIVER PARA SUAS PROPRIEDADES.")
    @MapKey(columns = { @Column(name = "PROP_NAME", nullable = false) })
    @Column(name = "PROP_VALUE", nullable = false)
    @Comments({ @Comment(table = "DRV_MAP_PROPERTIES", value = "VALORES MAPEADOS DAS PROPRIEDADES DO DRIVER"),
            @Comment(table = "DRV_MAP_PROPERTIES", column = "COD_DRIVER_PROPS", value = "CÓDIGO DA ASSOCIAÇÃO DA PROPRIEDADE COM O VALOR"),
            @Comment(table = "DRV_MAP_PROPERTIES", column = "PROP_NAME", value = "NOME DA PROPRIEDADE DO DRIVER"),
            @Comment(table = "DRV_MAP_PROPERTIES", column = "PROP_VALUE", value = "VALOR DA PROPRIEDADE DO DRIVER") })
    public Map<String, String> getProperties() {
        return this.properties;
    }

    /**
     * @param properties the properties to set
     */
    public void setProperties(Map<String, String> properties) {
        this.properties = properties;
    }

}
